package com.xcity.game.battle.pve.employee.impl;

import com.xcity.game.battle.Battler;
import com.xcity.game.battle.pve.PlayerBattler;
import com.xcity.game.battle.pve.employee.EmployeeSkillBattleContext;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.employee.skill.EmployeeSkill;

public class RaiseAttackLastNTimesSkillContext extends EmployeeSkillBattleContext {

	private boolean valid;
	private int playerInitAttack;
	
	public RaiseAttackLastNTimesSkillContext(PlayerBattler player, EmployeeSkill ref) {
		super(player, ref);
		playerInitAttack = player.getAttack();
		int n = rnd.nextInt(GameStaticConfig.percentBase);
		if (n < ref.getTemplate().getInitVal(0)) {
			float ratio = ref.getTemplate().getInitVal(1);
			int attack = (int) (playerInitAttack + playerInitAttack * ratio / 100);
			player.setAttack(attack);
			valid = true;
		}
	}

	@Override
	public boolean trigger() {
		if (valid) {
			if (++triggeredTimes > ref.getTemplate().getInitVal(2)) {
				valid = false;
				player.setAttack(playerInitAttack);
			}
		}
		return true;
	}

}
